<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
var jsonObj=new Object();


$(function(){
	var collegeName = '${collegeName}';
	//弹出框设置
	$("#dialogDiv").dialog({
		title:"账户维护",//标题
		width: 600,//宽度
	    height: 260,//高度
	    top:35,
	    closed: true,//初始关闭
	    cache: false,//缓存
	    modal: true,
	    onClose: function() {
			 $("#dialogIframe").attr("src","");
			} 
	});
	
	$("#searchButton").click(function(){
		$('#usermanagementList').datagrid({ queryParams:getParams()});
	});
	
	$("#empty").click(function(){
		$("#cnName").textbox('setValue',"");
		$("#college").textbox('setValue',"");
		$("#grade").textbox('setValue',"");
		$("#userName").textbox('setValue',"");
		$('#usermanagementList').datagrid({ queryParams:getParams()});
	});
	
	$("#editButton").click(function(){
		if($("input[name='studentId']:checked").size()==1){
			$("#dialogIframe").attr("src","<c:out value='/cup/editUserManagement.action' />?studentId="+$("input[name='studentId']:checked").val());
			$("#dialogDiv").dialog('open');
		}else{
			$.messager.alert('提示','请选择一条数据再编辑');
		}
	});
	
	$("#addButton").click(function(){
		var storiedBuilding = $("#storiedBuilding").val();
		$("#dialogIframe").attr("src","<c:out value='/cup/addUserManagement.action' />?storiedBuilding="+storiedBuilding);  //?storiedBuilding="+storiedBuilding
		$("#dialogDiv").dialog('open');
	});
	
	$("#deleteButton").click(function(){
		var studentId = ""
		var checkedObj=$("input[name='studentId']:checked");
		if(checkedObj.size()==1){
			studentId = $("input[name='studentId']:checked").val();
			$.messager.confirm({
				title:'提示',
				msg:'确定删除吗，确认将关联删除其他业务相关的记录',
				top:35,
				fn:function(r){
					if(r){
						$.ajax({
							type:'POST',
							url:'UserManagementDelete.action',
							data:{studentId:studentId},
							datatype:'json',
							success:function(msg){
								if(msg.state == "200"){
									$('#usermanagementList').datagrid({ queryParams:getParams()});
								}else{
									$.messager.alert("提示","删除失败");
								}
							}
						});
					}
				}
			});
		}else{
			$.messager.alert("提示","选择一条记录请");
		}
	});
	
	
	$('#usermanagementList').datagrid({
	    url:'<c:url value="ListForUser.action"/>',
	    queryParams:getParams(),//提交参数
	    toolbar:'#carCategoryToolbar',//表头工具栏
	    pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
	    pageList:[10, 20, 30, 40], 
	    fitColumns:true,
	    //checkOnSelect:true,
	    selectOnCheck:false,
	    sortName: 'userName',
	    sortOrder: 'asc',
	    remoteSort: false,
	    singleSelect:false,
	    //fitColumns:false,
	    //multiSort:true,
	    rownumbers:true,
	    //checkOnSelect:true,
	    striped:true,
	    //singleSelect:false,
	    //singleSelect:true,
	    columns:[[
			{field:'studentId',title:'',formatter: function(value,row,index){
				return '<input name="studentId" type="checkbox" value="'+value+'" />';
			}},
			{field:'userName',title:'账户',width:100,align:'center',sortable:true},
			{field:'cnName',title:'姓名',align:'center',width:100},
			{field:'sex',title:'性别',align:'center',width:100},
			{field:'college',title:'学院',align:'center',width:150},
			{field:'theClass',title:'班级',align:'center',width:100},
			{field:'grade',title:'年级',align:'center',width:100},
			{field:'disable',title:'账户禁用',align:'center',width:50,editor:{type:'checkbox',options:{on:1,off:0}},formatter : function(value, row, index) {
				if(value==0)
					 return '【禁用】';
					else
					return '启用';
				},}
	    ]],
	   onClickRow:function(index,row){
	    $("input[type=checkbox]").val([row.studentId]).attr("checked",true);
	    }
	});
	
	
	
});


//查询条件生成方法
function getParams(){
	if($("#userName").val()!="" && $("#userName").val()!=null){
		jsonObj.userName=$("#userName").val();
	}else{
		jsonObj.userName=null;
	}
	if($("#cnName").val()!="" && $("#cnName").val()!=null){
		jsonObj.cnName=$("#cnName").val();
	}else{
		jsonObj.cnName=null;
	}
	if($("#college").val()!="" && $("#college").val() != null){
		jsonObj.college = $("#college").val();
	}else{
		jsonObj.college = null;
	}
	if($("#grage").val()!="" && $("#grade").val() != null){
		jsonObj.grade = $("#grade").val();
	}else{
		jsonObj.grade = null;
	}
	if($("#storiedBuilding").val()!="" && $("#storiedBuilding").val()!=null){
		jsonObj.storiedBuilding=$("#storiedBuilding").val();
	}else{
		jsonObj.storiedBuilding=null;
	}
	if($("#studentId").val()!="" && $("#studentId").val()!=null){
		jsonObj.studentId=$("#studentId").val();
	}else{
		jsonObj.studentId=null;
	}
	//alert(list);
	//var judge = $("#Judge").val();
	//var judge = ${judge};
	//jsonObj.type_ =judge;
	return jsonObj;
}

//关闭弹出框
function closeDialog(){
	$('#usermanagementList').datagrid({ queryParams:getParams()});
	$('#dialogDiv').dialog('close');
}

